﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using RabbitMQ.Client;
using RabbitMQ.Client.Exceptions;

namespace ATPlatforms.RabbitSkin
{
    public class FanoutProducer<T> :  BaseProducerConsumer<T>
    {
        public FanoutProducer()
            : base()
        {
            MyExchangeType = ExchangeType.Fanout;
        }

        public void SendMessage(T message)
        {
            if(Model == null) throw new InvalidOperationException("Producer not running, please call Start()");
            IBasicProperties basicProperties = Model.CreateBasicProperties();
            Model.BasicPublish(Exchange, "", false, false, basicProperties, MessageSerializer.SerializeMessage(message));
        }


        public override bool OnStart(string routingKey)
        {
           //no queue needed
            return true;
        }
    }
}